home *** CD-ROM | disk | FTP | other *** search
- unit Cut_main;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, ExtCtrls, Menus, StdCtrls, WinCrt;
-
- type
- TForm1 = class(TForm)
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- Exit1: TMenuItem;
- N1: TMenuItem;
- PrintSetup1: TMenuItem;
- Print1: TMenuItem;
- N2: TMenuItem;
- SaveAs1: TMenuItem;
- Open1: TMenuItem;
- OpenDialog1: TOpenDialog;
- procedure Open1Click(Sender: TObject);
- procedure Exit1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure ApplicationActivate(Sender: TObject);
- procedure FormResize(Sender: TObject);
-
- private
- { Private 宣言 }
- public
- { Public 宣言 }
- end;
-
- var
- Form1: TForm1;
- cutSize: Longint;
- cut_x, cut_y: Integer;
- cutBmp: TBitmap;
- isDraw: Integer;
- function cutType(Ptr:PChar): Boolean;
- function expand1(org:PChar; count:Integer; cond:PChar): Integer;
- function expand2(org2:PChar; count2:Integer; cond2, lbuff:PChar): Integer;
- function cutPrint(xbuff: PChar; cutWidth, ofset: Integer): Boolean;
- function cutRedraw(iscc: Integer): Boolean;
-
- implementation
-
- {$R *.DFM}
-
- procedure Tform1.Open1Click(Sender: TObject);
- type
- bytePtr = ^Char;
- var
- f: file of Byte;
- fileHdl, i: Integer;
- cutPt, cutPt2, nstr: PChar;
- buf: Char;
- header, buff: String;
- begin
- if OpenDialog1.Execute then
- begin
- { Get CutFileSize }
- AssignFile(f, OpenDialog1.FileName);
- Reset(f);
- cutSize := FileSize(f);
- CloseFile(f);
- { CutTypeProcced }
- if MaxAvail < cutSize then
- MessageDlg('Not enough memory', mtWarning, [mbOk], 0)
- else
- begin
- { Get Bitmap }
- if (isDraw = 1) then cutBmp.free;
- cutBmp := TBitmap.create;
- { Get Memory}
- GetMem(cutPt, cutSize);
- { fileRead & Close }
- fileHdl := FileOpen(OpenDialog1.FileName, OF_SHARE_COMPAT);
- FileRead(fileHdl, cutPt^, cutSize);
- FileClose(fileHdl);
- { CutFile? }
- cutPt2 := cutPt;
- GetMem(nstr, 64);
- StrPas(StrMove(nstr, cutPt, 48));
- Inc(cutPt,48);
- if (compareText('CUT_V', Copy(StrPas(nstr),1,5)) = 0) then
- cutType(cutPt);
- { Dispose Memory }
- FreeMem(nstr, 64);
- FreeMem(cutPt2, cutSize);
- { Bitmap To Form.Canvas }
- form1.canvas.draw(0,0,cutBmp);
- isDraw := 1;
- end;
-
- end;
- end;
-
- procedure Tform1.Exit1Click(Sender: TObject);
- begin
- close;
- end;
-
- function cutType(Ptr:PChar): Boolean;
- var
- xx, yy, xsize, image_y, i: Integer;
- sstr, buffer, bufferPt: PChar;
- head, body: PChar;
- con1, con2, con1buff: PChar;
- dmy, j, y_ofset: integer;
- dmyStr: String;
- dmynull: PChar;
- lineBuf: PChar;
- cutRc: TRect;
- begin
- { CutSize? xx,yy }
- GetMem(sstr, 10);
- xx := Integer(Ptr^) * 256;
- Inc(Ptr, 1);
- xx := xx + Integer(Ptr^);
- Inc(Ptr, 1);
- yy := Integer(Ptr^) * 256;
- Inc(Ptr, 1);
- yy := yy + Integer(Ptr^);
- Inc(Ptr, 1);
- FreeMem(sstr, 10);
- { BitMap }
- cutBmp.canvas.brush.color := clGreen;
- cutBmp.canvas.FillRect(cutRc);
- cutBmp.width := xx;
- cutBmp.height := yy;
- cutBmp.Monochrome := False;
- { Set Cursor crHourGlass }
- screen.cursor := crHourGlass;
- { typeCut }
- GetMem(buffer, 256*16);
- GetMem(con1, 256);
- GetMem(con2, 256);
- GetMem(lineBuf, 256);
- xsize := (xx - 1) div 8 + 1;
- image_y := 0;
- y_ofset := -16;
- bufferPt := buffer;
-
- GetMem(dmyNull, 10);
-
- expand2(buffer, 0, con2, lineBuf);
- for i:=1 to yy do
- begin
- con1buff := con1;
- dmy := Integer(Ptr^);
- for j:=1 to dmy do
- begin
- con1buff^ := Ptr^;
- Inc(Ptr, 1);
- Inc(con1buff, 1);
- end;
- dmy := Integer(con1^);
-
- if (dmy<=0) then break;
- expand1(con2, xsize, con1);
- expand2(buffer, xsize, con2, lineBuf);
- Inc(buffer, xsize);
-
- Inc(image_y, 1);
- Inc(y_ofset, 1);
- if (image_y = 16) then
- begin
- image_y := 0;
- buffer := bufferPt;
- cutPrint(buffer, xx, y_ofset);
- end;
- end;
- if (image_y > 0) then
- begin
- buffer := bufferPt;
- cutPrint(buffer, xx, y_ofset);
- end;
- FreeMem(lineBuf, 256);
- FreeMem(con2, 256);
- FreeMem(con1, 256);
- FreeMem(bufferPt, 256*16);
- { Reset FormSize }
- form1.caption := ExtractFileName(form1.opendialog1.filename)+' ('+IntToStr(xx)+','+IntToStr(yy)+')';
- cutRc := Rect(0,0,xx,yy);
- form1.clientwidth := xx;
- form1.clientheight := yy;
- { Reset Cursor crHDefault }
- screen.cursor := crDefault;
- end;
-
- function expand1(org:PChar; count:Integer; cond:PChar): Integer;
- var
- pt, bt, flag, i: Integer;
- head, body: PChar;
- begin
- if (cond^ = Chr(1))then
- begin
- for pt:=1 to count do
- begin
- org^ := Chr(0);
- Inc(org, 1);
- end;
- expand1 := count;
- exit;
- end;
- pt := (count - 1) div 8 + 1;
- head := cond + 1;
- body := head + pt;
- for i:= 1 to Pt do
- begin
- flag := Integer(head^);
- Inc(head, 1);
- for bt:=0 to 7 do
- begin
- if ((flag And 128) = 0) then
- org^ := Chr(0)
- else
- begin
- org^ := body^;
- Inc(body, 1);
- end;
- Inc(org, 1);
- flag := flag shl 1;
- end;
- end;
- expand1 := count;
- end;
-
- function expand2(org2:PChar; count2:Integer; cond2, lbuff:PChar): Integer;
- var
- c: Integer;
- begin
- if (count2 = 0) then
- begin
- for c := 1 to 128 do
- begin
- lbuff^ := Char(0);
- Inc(lbuff, 1);
- end;
- expand2 := count2;
- exit;
- end;
- for c:=1 to count2 do
- begin
- org2^ := Chr(Integer(cond2^) Xor Integer(lbuff^));
- lbuff^ := org2^;
- Inc(org2, 1);
- Inc(cond2, 1);
- Inc(lbuff, 1);
- end;
- expand2 := count2;
- end;
-
- function cutPrint(xbuff: PChar; cutWidth, ofset: Integer): Boolean;
- var
- cr: PChar;
- flg2: Integer;
- i,j,k,ke:Integer;
- x_offset, cll, cll2: Integer;
- begin
- if ((ofset mod 16) = 0) then
- ke := 15
- else
- begin
- ke := ofset Mod 16 - 1;
- ofset := ofset + 16 - ke - 1;
- end;
- for k:= 0 to ke do
- begin
- cutBmp.canvas.pen.color := clGreen;
- cutBmp.canvas.MoveTo(-1,ofset + k);
- for i:=0 to (cutWidth div 8)-1 do
- begin
- flg2 := 128;
- x_offset := i*8;
- for j:=0 to 7 do
- begin
- if ( Integer(xbuff^) And flg2 <> 0) then
- cll := 1
- else
- cll := 0;
- if (cll <> cll2) then
- begin
- if (cll = 1) then
- begin
- cutBmp.canvas.pen.color := clGreen;
- cutBmp.canvas.moveTo(x_offset+j,ofset + k);
- end;
- if (cll = 0) then
- begin
- cutBmp.canvas.pen.color := clWhite;
- cutBmp.canvas.LineTo(x_offset+j,ofset + k);
- end;
- cll2 := cll;
- end;
- flg2 := flg2 shr 1;
- end;
- Inc(xbuff, 1);
- end;
- if ((cutWidth mod 8) > 0) then
- begin
- flg2 := 128;
- x_offset := (i+1)*8;
- for j:=0 to (cutWidth mod 8) do
- begin
- if ( Integer(xbuff^) And flg2 <> 0) then
- cll := 1
- else
- cll := 0;
- if (cll <> cll2) then
- begin
- if (cll = 1) then
- begin
- cutBmp.canvas.pen.color := clGreen;
- cutBmp.canvas.moveTo(x_offset+j,ofset + k);
- end;
- if (cll = 0) then
- begin
- cutBmp.canvas.pen.color := clWhite;
- cutBmp.canvas.LineTo(x_offset+j,ofset + k);
- end;
- cll2 := cll;
- end;
- flg2 := flg2 shr 1;
- end;
- Inc(xbuff, 1);
- end;
- if (cll = 0) then
- begin
- cutBmp.canvas.pen.color := clGreen;
- cutBmp.canvas.lineTo(cutWidth,ofset + k);
- end;
- if (cll = 1) then
- begin
- cutBmp.canvas.pen.color := clWhite;
- cutBmp.canvas.LineTo(cutWidth,ofset + k);
- end;
- end;
- end;
-
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- isDraw := 0;
- Application.OnActivate := ApplicationActivate;
- end;
-
- procedure TForm1.ApplicationActivate(Sender: TObject);
- begin
- cutRedraw(isDraw);
- end;
-
- function cutRedraw(iscc: Integer): Boolean;
- begin
- if (iscc > 0) then
- form1.canvas.draw(0,0,cutBmp);
- end;
-
-
- procedure TForm1.FormResize(Sender: TObject);
- begin
- if (isDraw > 0) then
- form1.canvas.draw(0,0,cutBmp);
- end;
-
- end.
-